﻿@model List<chihuopig.DTO.RoleModel>
@section Header{

}
<div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>角色名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">
                拥有权限
            </label>
            <table class="layui-table layui-input-block">
                <tbody>
                    @foreach (var item in Model)
                    {

                        <tr>
                            <td>
                                @item.MenuName
                            </td>
                            <td>
                                <div class="layui-input-block">
                                   @if (!string.IsNullOrWhiteSpace(item.JurisAny))
                                   {
                                       var ModeList = item.JurisAny.Split(',');
                                       foreach (var vl in ModeList)
                                       {
                                           string[] chen = vl.Split('-');
                                          <input name="JurisAny"  lay-skin="primary" title="@chen[0]" type="checkbox" id="@chen[1]" value="2">  
                                       }

                                   }
                               
                                </div>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div class="layui-form-item">
            <input type="button" onclick="btnsvae()" class="layui-btn"  value="增加" />
        </div>
    </form>
</div>
@section footer{
    <script>
        function btnsvae() {
            var listar = [];
            $("input[name='JurisAny']:checked").each(function (index, item) {
                listar.push($(item).attr("id"));
                //alert($(item).attr("id"));
            });

            if ($("input[name='name']").val()=="") {

                layer.msg('角色名不能为空', { icon: 2 });
                return;
            }

            if ($("input[name='name']").val().length > 20)
            {
                layer.msg('角色名的长度都大于20', { icon: 2 });
                return;
            }
            if (listar.length<=0)
            {
                layer.msg('请选择权限', { icon: 2 });
                return;
            }
            $.post("../adminrole/roleadd",
            {
                "RoleName": $("input[name='name']").val(),
                "jurisd": listar
            }, function (data) {

                if (!data.succeed) {

                    layer.msg(data.msg);

                }
                else
                {
                    layer.msg(data.msg);
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                }
            })
           
            
        }
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;


          $("input[name='checkMenuName']").click(function () {
              alert("fdsf");

          })



        });
    </script>
}